<?php
/**
 * Class descript.
 * User: chan
 * Date: 2017/10/20 11:22
 */

namespace app\api\controller;
use app\api\service\Nearby;
use app\api\model\Member as MemberModel;
use app\api\validate\test as testValidate;

class Test extends Base
{
    //检查权限作用域
//    protected $beforeActionList  = [
//        'checkPrimaryScope' => [
//            'only' => 'test,getUserInfoByToken'
//        ],
//    ];
    public function test()
    {
        //////////////////验证请求场景//////////////////////////////////////////
        //验证请求参数方式一
        $mobile = $this->checkParameter('mobile');
        $data = $this->checkParameters($this->requestData);
//        $data = [
//            'mobile'=>  $mobile,
//            'province'=>'',
//            'city'=>'',
//            'county'=>'',
//            'headimage'=>'',
//            'nickname'=>'',
//            'sex'=>''
//        ];

        //验证请求参数方式二
        //(new LoginValidate())->checkParam();

        //////////////////业务场景//////////////////////////////////////////
        //通过权限获取用户信息
        // var_dump($this->user);
    }

    /**
     * 生成token （上线后需要关闭测试方法)
     * @return \think\response\Json
     *
     */

    public function generateToken()
    {
        $user =  MemberModel::getByUID($this->requestData['userId']);
        $user['uid']= $user['id'];
        $user['userId']= $user['id'];
        $Oauth2 = new \app\api\service\Oauth2();
        return json($Oauth2::generateToken($user));
    }

    /**
     * 获取用户信息 （上线后需要关闭测试方法)
     *
     */
//    public function getUserInfoByToken()
//    {
//        $access_token = $this->requestData['access_token'];
//        $Oauth2 = new \app\api\service\Oauth2();
//        return json($Oauth2->getUserInfoByToken($access_token));
//    }

    /**
     * 参数验证
     */
    public function validateParam()
    {
        (new testValidate())->checkLoginParam();
        return $this->ajaxReturn($this->requestData);
    }
}